# -*-coding:utf-8-*-
__author__ = 'nickleo'

import jsonpickle as json
import http_client as http


def get_messages(type, namesvr, typeValue, key):
    statusCode = 200
    alert = 'ok'
    messages = None
    print '-----------------get_messages', type, namesvr, typeValue, key

    if type == 'msgkey':
        http_msg_query = http.get_message_key(namesvr, key, typeValue)

        if http_msg_query is None or http_msg_query.strip() == '':
            alert = 'nameserver:' + namesvr +  ' not found '
            statusCode = 404
        else:
            messages = http_msg_query

    return statusCode, alert,messages


def get_message_by_id(namesvr, id):
    statusCode = 200
    alert = 'ok'
    message = None
    print '-----------------get_message_by_id', namesvr, id

    http_msg_query = http.get_message_id(namesvr, id)
    if http_msg_query is None or http_msg_query.strip() == '':
        alert = 'nameserver:' + namesvr + 'id:' + id + ' not found '
        statusCode = 404
    else:
        message = http_msg_query

    return statusCode, alert, message